/*
 * CreateStyleAction.java
 * 
 * Created by demory on Feb 15, 2010, 8:13:28 PM
 * 
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.fpdev.apps.cart.actions;

import org.fpdev.apps.cart.Cartographer;
import org.fpdev.apps.cart.Editor;
import org.fpdev.apps.cart.network.LineStyle;

/**
 *
 * @author demory
 */
public class CreateLineStyleAction extends EditorBasedAction {

  private LineStyle style_;

  public CreateLineStyleAction(Editor ed) {
    this(ed, new LineStyle());
  }

  public CreateLineStyleAction(Editor ed, LineStyle style) {
    super(ed);
    style_ = style;
  }

  public boolean doAction(Cartographer cart) {
    ed_.getDocument().getStyles().addStyle(style_);
    cart.getGUI().getControlFrameManager().getStylesFrame().addStyle(style_);
    cart.getGUI().getControlFrameManager().getLinesFrame().refreshStyles(ed_.getDocument().getStyles().getList());
    return true;
  }

  public boolean undoAction(Cartographer cart) {
    ed_.getDocument().getStyles().removeStyle(style_);
    cart.getGUI().getControlFrameManager().getStylesFrame().removeStyle(style_);
    cart.getGUI().getControlFrameManager().getLinesFrame().refreshStyles(ed_.getDocument().getStyles().getList());
    return true;
  }

  public String getName() {
    return "Create Style";
  }

}
